package org.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.entity.system.User;
import org.example.entity.task.AttackTask;
import org.example.mapper.AttackTaskMapper;
import org.example.service.AttackTaskService;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @author 魏锴
 * @description 针对表【tb_task_attack】的数据库操作Service实现
 * @createDate 2024-01-11 18:23:57
 */
@Service
public class AttackTaskServiceImpl extends ServiceImpl<AttackTaskMapper, AttackTask>
        implements AttackTaskService {

    @Override
    public boolean insertTask(AttackTask attackTask) {
        return baseMapper.insertTask(attackTask);
    }

    @Override
    public boolean updateTask(AttackTask attackTask) {
        if (attackTask.getStartTime() == null && attackTask.getTaskStatus() == 1)
            attackTask.setStartTime(new Date());
        if (attackTask.getEndTime() == null && attackTask.getTaskStatus() == 2)
            attackTask.setEndTime(new Date());
        return baseMapper.updateTask(attackTask);
    }

    @Override
    public boolean deleteTask(int id) {
        return baseMapper.deleteTask(id);
    }

    @Override
    public AttackTask getAttackById(int id) {
        return baseMapper.getAttackById(id);
    }

    @Override
    public List<AttackTask> getTaskList() {
        List<AttackTask> tasks = baseMapper.getTaskList();
        for (AttackTask task : tasks)//添加测试者信息
            task.setJoinedTesters(baseMapper.getTesters(task.getId()));
        return tasks;
    }

    @Override
    public boolean publishTask(int id) {
        return baseMapper.publishTask(id);
    }

    @Override
    public boolean insertTester(int task_id, int user_id) {
        return baseMapper.insertTester(task_id, user_id);
    }

    @Override
    public boolean deleteTester(int id) {
        return baseMapper.deleteTester(id);
    }

    @Override
    public List<User> getTesterInfo() {
        return baseMapper.getTesterInfo();
    }


}




